package com.han.service.impl;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doudian.open.api.token.AccessTokenData;
import com.han.core.domain.entity.Shop;
import com.han.mapper.ShopMapper;
import com.han.service.ShopService;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
 * @author Administrator
 * @description 针对表【shop】的数据库操作Service实现
 * @createDate 2024-06-18 11:00:06
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop>
        implements ShopService {
    @Override
    public Boolean saveNewShop(AccessTokenData accessTokenData, Integer buyDays) {
        Long shopId = Long.valueOf(accessTokenData.getShopId());
        Shop shop = this.getById(shopId);
        if (null == shop) {
            shop = new Shop();
            shop.setShopId(shopId);
            shop.setShopName(accessTokenData.getShopName());
            shop.setBuyDays(buyDays);
            Date now = DateUtil.date();
            shop.setStartTime(now);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(Calendar.DAY_OF_WEEK, buyDays);
            shop.setEndTime(calendar.getTime());
            shop.setCreateTime(new Date());
            shop.setUpdateTime(new Date());
            this.save(shop);
            return true;
        }
        return false;
    }
}




